package com.sugar.junit.test;

import java.util.Random;

public class InitData {

	
	/*public static void main(String []args) {
		Session session = HibernateManager.getSession() ;
		
		for(int i=0;i<20;i++) {
			HqlUserBean h = new HqlUserBean() ;
			h.setUserName(data("name")) ;
			h.setAge(Integer.parseInt(data("age"))) ;
			h.setSex(data("sex")) ;
			h.setClasses(Integer.parseInt(data("classes"))) ;
			
			session.beginTransaction() ;
			session.save(h) ;
			session.beginTransaction().commit() ;
			
		}
		HibernateManager.close(session) ;
		
	}*/
	
	// 测试数据
	public static String data(String val) {

		String name = "捡到了搜网口味电脑使大家品味起来考虑第五路口苏东坡是到拉萨打破其间的撒旦我就" ;
		String age = "1234567890";
		String sex = "男女";
		String classes = "1234" ;

		Random r = new Random();

		StringBuffer sb = new StringBuffer();

		if ("name".equals(val)) {
			for (int i = 0; i < 3; i++) {
				int number = r.nextInt(name.length());
				sb.append(name.charAt(number));
			}
		} else if("age".equals(val)) {
			for (int i = 0; i < 2; i++) {
				int number = r.nextInt(age.length());
				sb.append(age.charAt(number));
			}
		} else if("sex".equals(val)) {
			for (int i = 0; i < 1; i++) {
				int number = r.nextInt(sex.length());
				sb.append(sex.charAt(number));
			}
		} else {
			for (int i = 0; i < 1; i++) {
				int number = r.nextInt(classes.length());
				sb.append(classes.charAt(number));
			}
		}
		return sb.toString();
	}
}
